
function addformgallery()
{
   $("#addform").append('<div id="feature'+rowdiv+'" class="itPlg addGalPlg featureclass">'+dataform['gallery']+"</div>");
   var rownow=rowdiv;
//   var $form = $('#feature'+rownow+' .royalSlider');
//   $('#feature'+rownow+' .group').colorbox({
//preloading: true,
//modal: true,
//transition: 'none',
//speed: 0, 
//transition:"fade",
//onComplete: function(e) {
//            currRs = $('#cboxLoadedContent').find('.royalSlider').royalSlider({
              //imageScaleMode: 'fill',
//              imageScaleMode:'fit',
//              autoScaleSlider:true,
//              autoHeight:true
//             
//            }).data('royalSlider');
         //   updateLightboxSize();
//},

//          inline:true, 
//          href:$form

//});
//   win.resize( function() {
    // updateLightboxSize();
//  });
  var rowg=1;
  for(rowg=1;rowg<5;rowg++)
  {
  var rowgnow=rowg;
  
  
   $('#feature'+rownow+' .image'+rowgnow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(150,150,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];
         
         //console.log(rowgnow2);
         
         $('#feature'+rownow+' .image'+rowgnow2+' .plgAreaGallery').html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
     //    $('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow2-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
       //  $('#feature'+rownow+' .rsSlide  img').eq((rowgnow2-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
         
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);
         
         
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);
         
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);
         
         
         $("#imgmid-"+setting.id).val(setting.imgmid);
         
         $("#simgmid-"+setting.id).val(imgmid2);
         
         
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);
         
         closepopup();
         
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
  
   $('#feature'+rownow+' .image'+rowgnow+' .cloudbutton').click(function() {
          //var rowgnow3=rowgnow;
          var rowgnow3=$(this).attr("class").split('cloudset').pop();
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
        // $('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",filelink2+'?t='+Math.floor((Math.random()*100000)+1));
         $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaGallery').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
         closepopup();

          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            
           // $('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
           // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,rowgnow
          ,150
          ,150
          
          );

   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .deletebutton').click(function() {
   
   var rowgnow3=$(this).attr("class").split('deleteset').pop();
   
   
  // $('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",'/images/default/noimage.png'+'?t='+Math.floor((Math.random()*100000)+1));
 //  $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",'/images/default/noimage.png'+'?t='+Math.floor((Math.random()*100000)+1));
//   $('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",'/images/default/noimage.png'+'?t='+Math.floor((Math.random()*100000)+1));

    $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaGallery a').remove();   
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
    $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
     
     
     $('#feature'+rownow+' .image'+rowgnow3+' textarea').val('');
   
   });
   var linsetmaindata='';
   $('#feature'+rownow+' .image'+rowgnow+' .linkbutton').click(function() {
   var rowgnow3=$(this).attr("class").split('linkset').pop();
   
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         //$('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",filelink2+'?t='+Math.floor((Math.random()*100000)+1));
         
         $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaGallery').html('<a target="_blank" href="'+linsetmaindata+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
         closepopup();

          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            
            linsetmaindata=filelink;
       //     $('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
      //      $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,rowgnow
          ,150
          ,150
   
   );
   
   });
   
      $('#feature'+rownow+' .deleterowbutton').click(function(){
   
    $('#feature'+rownow).remove();
    
   });
  
  
  }
  
 
  
  
  
  
  
  
  
  
  
  
  
  //$('#feature'+rownow+' .group')
   
   
  
   

  
  
   rowdiv++;
}

function saveformgallery(id,plugid)
{
var obj={};
var imgmid1,imgmid2,imgmid3,imgmid4,detail;
var simgmid1,simgmid2,simgmid3,simgmid4;
var detail1,detail2,detail3,detail4;
var krow=0

       imgmid1=$("#"+id+' .image1 input[name="imgmid[]"]').val();
       imgmid2=$("#"+id+' .image2 input[name="imgmid[]"]').val();
       imgmid3=$("#"+id+' .image3 input[name="imgmid[]"]').val();
       imgmid4=$("#"+id+' .image4 input[name="imgmid[]"]').val();
       
       
       simgmid1=$("#"+id+' .image1 input[name="simgmid[]"]').val();
       simgmid2=$("#"+id+' .image2 input[name="simgmid[]"]').val();
       simgmid3=$("#"+id+' .image3 input[name="simgmid[]"]').val();
       simgmid4=$("#"+id+' .image4 input[name="simgmid[]"]').val();
       
       detail1=$("#"+id+' .image1 textarea').val();
       detail2=$("#"+id+' .image2 textarea').val();
       detail3=$("#"+id+' .image3 textarea').val();
       detail4=$("#"+id+' .image4 textarea').val();
       imgmids=new Array();
       if(imgmid1!="")
       {
       imgmids[krow]={imgmid:imgmid1,simgmids:simgmid1,detail:detail1};
       krow++;
       
       }
       
       if(imgmid2!="")
       {
       imgmids[krow]={imgmid:imgmid2,simgmids:simgmid2,detail:detail2};
       krow++;
       
       }
       
       if(imgmid3!="")
       {
       imgmids[krow]={imgmid:imgmid3,simgmids:simgmid3,detail:detail3};
       krow++;
       
       }
       
       if(imgmid4!="")
       {
       imgmids[krow]={imgmid:imgmid4,simgmids:simgmid4,detail:detail4};
       krow++;
       
       }
       
       
       
       
       obj={plugid:plugid,imgmids:imgmids};
       
       
       
       
       return obj;
       
       
}
function getformgallery(dataplugin)
      {

var code="";
var rowcheck=0;
if(typeof  dataplugin['gallery']!= "undefined"&&dataplugin['gallery'].length)
{
code = '<div class="ldIt wrpGalLd">\n';

$.each(dataplugin['gallery'], function(key, value) {


if(value.imgmid==0)
{
rowcheck++;
}

code += '<div class="galLd w160" onclick="openmaingallery('+value.simgmid+')">\n';
code += '<div class="icoDefLd">\n';
code += '<span class="ico icoImgDefLd"></span>\n';
code += '<span>Image</span>\n';
code += '</div>\n';
code += '<div class="wrpImgDesGalLd">\n';
code += '<a href="javascript:void(0)"    class="galleryimage"><img title="'+value.img.newpath+'" width="160" height="160" alt="'+value.img.width+'|'+value.img.height+'" id="img-'+value.simgmid+'" src="'+value.simg.newpath+'"></a>\n';
code += '<div class="desGalLd clTxtW"  >\n';

var displayset="";
if(value.detail=="")
{
displayset='style="display:none"';
}

code += '<div class="ovlLd ovlGalLd w160" '+displayset+'>\n';
code += '<p class="cutTxt">'+value.detail+'</p>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
});
code += '<div class="emtGen"></div>\n';
code += '</div>';
}

if(rowcheck==4)
{
code="";
}




return code;


}

function editformgallery(datarow)
{
   addformgallery();
   var rownow= rowdiv-1;
   var rowgnow3=1;
   
   if(typeof  datarow['gallery']!= "undefined"&&datarow['gallery'].length)
   {
   $.each(datarow['gallery'], function(key, value) {
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(value.img.imgmid); 
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(value.simg.imgmid);
   $('#feature'+rownow+' .image'+rowgnow3+' textarea').val(value.detail);
   $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaGallery').html('<a target="_blank" href="'+value.img.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+value.simg.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
   rowgnow3++;
   });
   }
   

}